/**
 * 问卷调查
 * Created by KY on 2017/8/17.
 */
define(['ldfw/core','comps/ajax','comps/session','ldfw/ldlibs/dict','text!tpl/user/questionnaire.tpl',],
function(LDFW,ajax,session,dict,tpl){
    var View = LDFW.Container.extend({
        tpl:tpl,
        className:'panel',
        initialize:function(){
            this.on('shown',this.loadData)
        },
        loadData:function(){
            const _this = this
            let curr_cust = session.getCurrentUser()
            let paper_type = curr_cust.cust_type === 1?2:1
            ajax.post('cpliL.1.58', {cust_type: curr_cust.cust_type}).success(function (resp) {
                let result = resp.result
                if(result){
                    let risk_accept = '',
                        adapt_product = _this.getAdaptProduct(result.risk_accept)
                    if(curr_cust.cust_type===1){
                        risk_accept = dict.getDict('risk_accept_co', result.risk_accept)
                    }else if(curr_cust.cust_type===2){
                        risk_accept = dict.getDict('risk_accept_cust', result.risk_accept)
                    }
                    _this.model.set('risk_accept',risk_accept)
                    _this.model.set('adapt_product',adapt_product)
                    _this.model.set('risk_result',result.ques_invest_num+'分~')
                }
            })
            $.when(ajax.get('getPaper.do',{paper_type:paper_type}),ajax.post('cpliL.1.57',{cust_type:curr_cust.cust_type}))
                .done(function(xhr1,xhr2){
                    let questions = xhr1[0].questions,
                        answers = xhr2[0].result;
                    if(!_.isEmpty(questions) && !_.isEmpty(answers)){
                        questions.forEach(function(question,index){
                            if(question.quest_content === answers[index].quest_content){
                                question.opt_value = answers[index].opt_value
                            }
                        })
                    }
                    _this.model.set('questions',questions)
                    _this.paper_no = xhr1[0].paper_no
                    _this.render()
                })
        },
        getAdaptProduct:function(risk_accept){
            switch(risk_accept){
                case 0:
                    return '无'
                case 1:
                    return 'R1'
                case 2:
                    return 'R1,R2'
                case 3:
                    return 'R1,R2,R3'
                case 4:
                    return 'R1,R2,R3,R4'
                case 5:
                    return 'R1,R2,R3,R4,R5'
                default:
                    return 'R1,R2,R3,R4,R5'
            }
        }
    })
    return new View()
})